package itcast.web.servlet;

import itcast.domain.Build;
import itcast.domain.Score;
import itcast.service.BuildService;
import itcast.service.ScoredromService;
import itcast.service.impl.BuildServiceImpl;
import itcast.service.impl.ScoredromServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/addscore_dromServlet")
public class Addscore_dromServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.设置编码
        request.setCharacterEncoding("utf-8");
        //2.获取参数
        Map<String,String[]> map=request.getParameterMap();
        //3.封装对象
        Score score=new Score();
        try {
            BeanUtils.populate(score,map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        //4.调用Service保存
       ScoredromService service=new ScoredromServiceImpl();
        service.addscore_drom(score);
        //5.跳转到BuildServlet
        response.sendRedirect(request.getContextPath()+"/score_dromServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }
}
